#!/bin/bash
if [ -f build.version ]
then
 for each in $(egrep -v '^#' build.version)
 do
  case $each in
  version.major=*)
    major=$(echo $each | sed 's/.*=//');;
  version.minor=*)
    minor=$(echo $each | sed 's/.*=//');;
  version.build=*)
    build=$(echo $each | sed 's/.*=//');;
  esac
 done
 name="sagittarius-${major}.${minor}.${build}"
 source="${name}.jar"
 target="${name}.zip"
 if [ -f "${source}" ]
 then
  mkdir -p ${name}/lib

  for jarf in $(java -cp etc Libclasspath jogl lib)
  do 
   cp -p ${jarf} ${name}/lib
  done
  cp -p ${name}.jar ${name}
  if [ -d ~/ulsf-sagittarius ]
  then
    cp -r ~/ulsf-sagittarius ${name}
  fi
  cat<<EOF>${name}/README.txt
Version

    ${name}

Run

    In this directory, run the command

        java -jar ${source}

    (Or equivalent -- relative classpath defined in the jar manifest)

Additional resources

    Moving the subdirectory 'ulsf-sagittarius' to your home directory
    should make this resource available to the program.

EOF
  zip -r ${target} ${name}
  rm -rf ${name}
  ls -l ${target}
 else
  cat<<EOF>&2
Error, missing file '${source}'.
EOF
  exit 1
 fi
else
 cat<<EOF>&2
Error, missing file 'build.version'.
EOF
 exit 1
fi
